﻿using System;
using Token.Piker.Common;
using System.IO;

namespace Token.Piker.Web.Admin.Activity
{
    public partial class Add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (Session[GlobalConstants.PIKER_ADMIN] == null)
            {
                MessageBox.ShowAndRedirect(this.Page, "网络连接超时，请重新登录！", ResolveClientUrl("~/Admin/Login.aspx"));
                return;
            }
            if (!fileUp.HasFile)
            {
                MessageBox.Show(this.Page, "请选择背景图片！");
                return;
            }
            int Creator = Convert.ToInt32(Session[GlobalConstants.PIKER_ADMIN]);
            string Theme = this.txtTheme.Text;
            string Descrip = this.txtDescrip.Text;
            string Award = this.txtAward.Text;
            DateTime StartTime = DateTime.Parse(this.txtStartTime.Text);
            DateTime EndTime = DateTime.Parse(this.txtEndTime.Text);
            string Position = this.txtPosition.Text;
            int PartCount = 0;
            string BackgroundImg;
            string fileName = fileUp.FileName;
            string ext = Path.GetExtension(fileName);
            string path = "~/Admin/uploads/activity/";
            path = path + DateTime.Now.ToString("yyyyMMddhhmmss") + ext;
            BackgroundImg = path;
            fileUp.SaveAs(Server.MapPath(path));
            int Flag = int.Parse(ddlFlag.SelectedValue);

            Token.Piker.Model.Activity model = new Token.Piker.Model.Activity();
            model.Creator = Creator;
            model.Theme = Theme;
            model.Descrip = Descrip;
            model.Award = Award;
            model.StartTime = StartTime;
            model.EndTime = EndTime;
            model.Position = Position;
            model.PartCount = PartCount;
            model.BackgroundImg = BackgroundImg;
            model.Flag = Flag;

            Token.Piker.BLL.ActivityBLL bll = new Token.Piker.BLL.ActivityBLL();
            bll.Add(model);
            MessageBox.ShowAndRedirect(this, "保存成功！", "Add.aspx");
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("List.aspx");
        }
    }
}